<section class="page-hd">
    <header>
        <p class="title-description title-top">
            添加类型
        </p>
    </header>
    <hr>
</section>
<form method="post" id="newsForm" class="form-horizontal">
    <input type="hidden" name="id" value="{$model.id}">

    <div class="form-group-col-2">
        <div class="form-label">类型分类：</div>
        <div class="col-sm-5">
            <select style="width:auto;" name="pId" {if condition='!empty($pId)'}disabled{/if}>
                <option value="">请选择类型</option>
                {volist name="list" id="vo"}
                {if condition="$vo.id == $pId || $model.pId == $vo.id"}
                <option value="{$vo.id}" selected>{$vo.typeName}</option>
                {else/}
                <option value="{$vo.id}">{$vo.typeName}</option>
                {/if}
                {/volist}
            </select>
            {if condition='!empty($pId)'}
            <input type="hidden" name="pId" value="{$pId}">
            {/if}
            <span style="color: red;">添加子级时，类型分类不可再次选择</span>
        </div>
    </div>

    <div class="form-group-col-2">
        <div class="form-label">类型名称：</div>
        <div class="col-sm-5">
            <input type="text" name="typeName" placeholder="类型名称..." class="form-control form-boxed" value="{$model.typeName}">
        </div>
    </div>

    <div class="form-group-col-2">
        <div class="form-label">排序：</div>
        <div class="col-sm-5">
            <input type="text" name="sort" placeholder="排序..." class="form-control form-boxed form-width" value="{$model.sort}">
        </div>
    </div>

    <div class="form-group-col-2">
        <div class="form-label">状态：</div>
        <div class="col-sm-5">
            <label class="check-box">
                {if condition="$model.state == 0 || empty($model)"}
                <input type="checkbox" name="state" checked/>
                {else/}
                <input type="checkbox" name="state"/>
                {/if}
                <span>允许使用</span>
            </label>
        </div>
    </div>

    <div class="form-group-col-2">
        <div class="form-label"></div>
        <div class="col-sm-5">
            <input type="button" id="newsSubmit" class="btn btn-primary" value="添加类型" data-url="{:url('info/addAndUpdate')}"/>
        </div>
    </div>
</form>

<script>
    $('#newsSubmit').on('click', function () {
        var url = $(this).attr('data-url');
        Ajax(url, $('#newsForm').serialize());
    });
    function Ajax(url, data) {
        $.ajax({
            url: url,
            cache: false,
            dataType: 'json',
            data: data,
            type: 'post',
        }).done(function (res) {
            if (res.code == 200) {
                layer.alert(res.msg, function () {
                    location.href = res.url;
                });
            } else {
                layer.alert(res.msg);
            }
        }).fail(function (e) {
            layer.alert(e);
        });
    }
</script>